var httpInvoker = {
  post: function (url, params) {
    store.commit('showLoading');
    return axios({
      method: 'post',
      url: url,
      data: params,
      timeout: 20000,
    }).then(
      (response) => {
        store.commit('hideLoading');
        if(!response){
        }
        return response
      }
    ).catch((e) => {
      this.handleError(e);
      store.commit('hideLoading');
    })
  },
  get2: function (url, settings) {
    return axios.get(url, settings);
  },
  get: function (url, settings) {
    store.commit('showLoading');
    return axios.get(url, settings).then(
      (response) => {
        store.commit('hideLoading');
        return response
      }
    ).catch((e) => {
      this.handleError(e);
      store.commit('hideLoading');
    })
  }, handleError: function (e) {
    if(!e){
      app.$alert('Server Error', '', {
        confirmButtonText: '确定'
      });
    }else 
    if (e.response) {
      var status = e.response.status;
      if (status == '401') {
        sessionStorage.removeItem('loginUser');
        app.$alert(e.response.data.msg, '', {
          confirmButtonText: '确定',
          callback: action => {
            app.$router.push({ path: '/login' })
          }
        });
      }else{
        app.$alert('Server Error', '', {
          confirmButtonText: '确定'
        });
      }
    } else {
      app.$alert(e.message, '', {
        confirmButtonText: '确定'
      });
    }
  }
}

axios.defaults.headers.token = sessionStorage.token;
